﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Common;
using System.Data;

namespace SkWeb.RiskDB
{
    public partial class Handler11 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string resultJson = string.Empty;
                string format = "\"total\":{0}, \"rows\":{1}";

                int pageSize, pageIndex, recordCount;

                int.TryParse(Request.Form["rows"], out pageSize);
                int.TryParse(Request.Form["page"], out pageIndex);
                if (pageSize == 0) pageSize = 15;
                if (pageIndex == 0) pageIndex = 1;
                recordCount = 0;
              
                string jh = Request.Form["jh"];
                string fxjb = Request.Form["fxjb"];
                DataTable dt = QueryWellInfo(jh,fxjb, pageSize, pageIndex, out recordCount);
                Response.ContentType = "text/json";
       
                resultJson = JsonHelper.ToJson(dt);
                resultJson = "{" + string.Format(format, recordCount,
                       string.IsNullOrWhiteSpace(resultJson) ? "[]" : resultJson) + "}";
                Response.Write(resultJson);
                Response.End();
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
        }



        public DataTable QueryWellInfo(string wellCode,string fxjb, int pageSize, int pageIndex, out int recordCount)
        {
            string firstSql = @"SELECT A.ID,
                                   A.JH     ,
                                   A.JB     ,
                                   A.SKJD1  ,
                                   A.SKJD2  ,
                                   A.WJYMD  ,
                                   A.WJYMC  ,
                                   A.YGGG,A.SKQX, A.SKDX, A.SHR, A.LRR,
                                   A.ZLHSD, B.SH
                              FROM SKGYSJB A inner join  ZYSGSJ B on  A.ID = B.ID where 1=1 ";
            firstSql = @"select t.id ,t.name,t.lng,t.lat, t.jb,t.gy,t.rank,t.address,b.des from tb_wellinfo t left join tb_riskblockinfo b on  t.block_id=b.id  where 1=1 ";
            if (!string.IsNullOrWhiteSpace(wellCode))
            {
                firstSql += string.Format("  and t.name like '%{0}%' ", wellCode);
            }
            if (!string.IsNullOrWhiteSpace(fxjb))
            {
                firstSql += string.Format("  and t.rank ={0} ", fxjb);
            }

            firstSql += " order by t.id DESC";
            return DbHelperOra.ExecutePageQuery(firstSql, pageSize, pageIndex, out recordCount);
        }




    }
}